#lang racket

(require "rename-mutable-pair-ops.rkt")

(define (contains? seq el)
  (cond ((null? seq) false)
        ((eq? (car seq) el) true)
        (else (contains? (cdr seq) el))))

(define (cycled? l)
  (define path '())
  (define (check-pair x)
    (cond ((not (pair? x)) false)
          ((contains? path x) true)
          (else (begin (set! path (cons x path))
                       (check-pair (cdr x))))))
  (check-pair l))

(define last (cons 'l '()))

(define l (cons 'a (cons 'b last)))

(set-cdr! last l)

(cycled? l)

(cycled? (list 'a 'b 'c))

;(print-list l)